<!doctype html>
<html lang="en">
<!-- head 区域 - 开始 -->
<?php
$title='编辑平台网课';
require_once('head.php');
if($userrow['uid']!=1){exit("<script language='javascript'>window.location.href='login.php';</script>");}
?>
<!-- head 区域 - 结束 -->

<body data-topbar="dark" data-layout="horizontal">

  <!-- 页面 - 开始 -->
  <div id="layout-wrapper">

    <!-- 头部区域 - 开始 -->
    <?php include('header.php'); ?>
    <!-- 头部区域 - 结束 -->

    <!-- 顶部导航栏 - 开始 -->
    <?php include('topnav.php'); ?>
    <!-- 顶部导航栏 - 结束 -->

    <!-- 主内容区域 - 开始 -->
    <div class="main-content" id="orderlist">

      <div class="page-content">
        <div class="container-fluid">

          <div class="row mt-4">
            <div class="col-lg-12">
              <div class="card">
                <div class="card-body">
                  <!-- 表头 - 开始 -->
                  <div class="card-button"><button class="btn btn-primary waves-effect waves-light" data-toggle="modal"
                      data-target="#modal-add">添加平台</button></div>
                  <h4 class="card-title">平台列表</h4>
                  <p class="card-title-desc">这里乱添加会出问题</p>
                  <!-- 表头 - 结束 -->

                  <!-- 表体 - 开始 -->
                  <div class="table-responsive">
                    <table class="table table-hover mb-0">
                      <thead>
                        <tr>
                          <th>ID</th>
                          <th>名称</th>
                          <th>平台</th>
                          <th>账号</th>
                          <th>密码</th>
                          <th>网址</th>
                          <th>密钥</th>
                          <th>添加时间</th>
                          <th>操作</th>
                        </tr>
                      </thead>
                      <tbody>
                        <tr v-for="res in row.data" :key="res.hid">
                          <th scope="row">{{res.hid}}</th>
                          <td>{{res.name}}</td>
                          <td>{{res.pt}}</td>
                          <td>{{res.user}}</td>
                          <td>{{res.pass}}</td>
                          <td>{{res.url}}</td>
                          <td>{{res.token}}</td>
                          <td>{{res.addtime}}</td>
                          <td><button class="btn btn-info waves-effect waves-light btn-sm" data-toggle="modal"
                              data-target="#modal-update" @click="storeInfo=res">编辑</button></td>
                        </tr>
                      </tbody>
                    </table>
                  </div>
                  <!-- 表体 - 结束 -->

                  <!-- 分页 - 开始 -->
                  <?php include('pagination.php'); ?>
                  <!-- 分页 - 结束 -->

                </div>
              </div>
            </div>
          </div>
          <!-- end row -->

        </div> <!-- container-fluid -->
      </div>
      <!-- End Page-content -->

      <!-- 修改弹窗 - 开始 -->
      <div class="modal fade primary" id="modal-update">
        <div class="modal-dialog" role="document">
          <div class="modal-content">
            <div class="modal-header">
              <h4 class="modal-title">修改平台</h4>
              <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true"
                  style="font-size: 30px;">&times;</span>
              </button>
            </div>

            <div class="modal-body">
              <form class="form-horizontal" id="form-update">
                <input type="hidden" name="action" value="update" />
                <input type="hidden" name="hid" :value="storeInfo.hid" />
                <div class="form-group row">
                  <label class="col-lg-2 col-form-label">名称</label>
                  <div class="col-lg-10">
                    <input type="text" name="name" class="form-control" :value="storeInfo.name" placeholder="输入自定义名称">
                  </div>
                </div>
                <div class="form-group row">
                  <label class="col-lg-2 col-form-label">平台</label>
                  <div class="col-lg-10">
                    <select name="pt" class="form-control" :value="storeInfo.pt">
                      <?php
                        $a=wkname();
                        foreach($a as $key => $value){ 	                            		   	
                          echo	'<option value="'.$key.'">'.$value.'</option>';													
                        }
                      ?>
                    </select>
                  </div>
                </div>
                <div class="form-group row">
                  <label class="col-lg-2 col-form-label">域名</label>
                  <div class="col-lg-10">
                    <input type="text" name="url" class="form-control" :value="storeInfo.url" placeholder="输入域名">
                  </div>
                </div>
                <div class="form-group row">
                  <label class="col-lg-2 col-form-label">账号</label>
                  <div class="col-lg-10">
                    <input type="text" name="user" class="form-control" :value="storeInfo.user"
                      placeholder="输入账号,27对接填uid">
                  </div>
                </div>
                <div class="form-group row">
                  <label class="col-lg-2 col-form-label">密码</label>
                  <div class="col-lg-10">
                    <input type="text" name="pass" class="form-control" :value="storeInfo.pass"
                      placeholder="输入密码,27对接填key">
                  </div>
                </div>
                <div class="form-group row">
                  <label class="col-lg-2 col-form-label">密匙</label>
                  <div class="col-lg-10">
                    <input type="text" name="token" class="form-control" :value="storeInfo.token"
                      placeholder="输入密匙/token，没有则不输入">
                  </div>
                </div>
                <div class="form-group row">
                  <label class="col-lg-2 col-form-label">cookie</label>
                  <div class="col-lg-10">
                    <textarea name="cookie" placeholder="没必要，不用输入" class="form-control" :value="storeInfo.cookie"
                      rows="4"></textarea>
                  </div>
                </div>
              </form>
            </div>
            <div class="modal-footer">
              <button type="button" class="btn btn-secondary waves-effect" data-dismiss="modal">取消</button>
              <button type="button" class="btn btn-primary waves-effect waves-light"
                @click="form('update')">确定修改</button>
            </div>
          </div>
        </div>
      </div>
      <!-- 修改弹窗 - 结束 -->

      <!-- 新增弹窗 - 开始 -->
      <div class="modal fade primary" id="modal-add">
        <div class="modal-dialog" role="document">
          <div class="modal-content">
            <div class="modal-header">
              <h4 class="modal-title">添加平台</h4>
              <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true"
                  style="font-size: 30px;">&times;</span>
              </button>
            </div>

            <div class="modal-body">
              <form class="form-horizontal" id="form-add">
                <input type="hidden" name="action" value="add" />
                <div class="form-group row">
                  <label class="col-lg-2 col-form-label">名称</label>
                  <div class="col-lg-10">
                    <input type="text" name="name" class="form-control" placeholder="输入自定义名称">
                  </div>
                </div>
                <div class="form-group row">
                  <label class="col-lg-2 col-form-label">平台</label>
                  <div class="col-lg-10">
                    <select name="pt" class="form-control">
                      <?php
                        $a=wkname();
                        foreach($a as $key => $value){ 	                            		   	
                          echo	'<option value="'.$key.'">'.$value.'</option>';													
                        }
                      ?>
                    </select>
                  </div>
                </div>
                <div class="form-group row">
                  <label class="col-lg-2 col-form-label">域名</label>
                  <div class="col-lg-10">
                    <input type="text" name="url" class="form-control" placeholder="输入域名">
                  </div>
                </div>
                <div class="form-group row">
                  <label class="col-lg-2 col-form-label">账号</label>
                  <div class="col-lg-10">
                    <input type="text" name="user" class="form-control" placeholder="输入账号,27对接填uid">
                  </div>
                </div>
                <div class="form-group row">
                  <label class="col-lg-2 col-form-label">密码</label>
                  <div class="col-lg-10">
                    <input type="text" name="pass" class="form-control" placeholder="输入密码,27对接填key">
                  </div>
                </div>
                <div class="form-group row">
                  <label class="col-lg-2 col-form-label">密匙</label>
                  <div class="col-lg-10">
                    <input type="text" name="token" class="form-control" placeholder="输入密匙/token，没有则不输入">
                  </div>
                </div>
                <div class="form-group row">
                  <label class="col-lg-2 col-form-label">cookie</label>
                  <div class="col-lg-10">
                    <textarea name="cookie" placeholder="没必要，不用输入" class="form-control" rows="4"></textarea>
                  </div>
                </div>
              </form>
            </div>
            <div class="modal-footer">
              <button type="button" class="btn btn-secondary waves-effect" data-dismiss="modal">取消</button>
              <button type="button" class="btn btn-primary waves-effect waves-light" @click="form('add')">确定添加</button>
            </div>
          </div>
        </div>
      </div>
      <!-- 新增弹窗 - 结束 -->

      <!-- 底部版权区域 - 开始 -->
      <?php include('copyright.php'); ?>
      <!-- 底部版权区域 - 结束 -->

    </div>
    <!-- 主内容区域 - 结束 -->
  </div>
  <!-- 页面 - 结束 -->

  <!-- 底部文件 - 开始 -->
  <?php include('footer.php'); ?>
  <!-- 底部文件 - 结束 -->

  <script type="text/javascript">
    new Vue({
      el: "#orderlist",
      data: {
        row: null,
        storeInfo: {}
      },
      methods: {
        get: function (page) {
          // var load=layer.load(2);
          SlickLoader.setText('加载中...')
          SlickLoader.enable();
          this.$http.post("/apisub.php?act=huoyuanlist", { page: page }, { emulateJSON: true }).then(function (data) {
            // layer.close(load);
            SlickLoader.disable();
            if (data.data.code == 1) {
              this.row = data.body;
            } else {
              layer.msg(data.data.msg, { icon: 2 });
            }
          });
        },
        form: function (form) {
          // var load=layer.load(2);
          SlickLoader.setText('加载中...')
          SlickLoader.enable();
          this.$http.post("/apisub.php?act=uphuoyuan", { data: $("#form-" + form).serialize() }, { emulateJSON: true }).then(function (data) {
            // layer.close(load);
            SlickLoader.disable();
            if (data.data.code == 1) {
              this.get(this.row.current_page);
              $("#modal-" + form).modal('hide');
              layer.msg(data.data.msg, { icon: 1 });
              // 清空表单
              document.getElementById("form-add").reset();
            } else {
              layer.msg(data.data.msg, { icon: 2 });
            }
          });
        },
        bs: function (oid) {
          layer.msg(oid);
        }
      },
      mounted() {
        this.get(1);
      }
    });
  </script>

</body>

</html>